package payroll.classification;

import payroll.PaymentClassification;

import java.util.LinkedHashMap;
import java.util.Map;

public class CommissionedClassification implements PaymentClassification {

    private double salary;
    private double commission;
    private Map<String, SalesReceipt> salesReceipts = new LinkedHashMap<>();

    public CommissionedClassification(double salary, double commission) {
        this.salary = salary;
        this.commission = commission;
    }

    public double getSalary() {
        return salary;
    }

    public double getCommissionRate() {
        return commission;
    }

    public SalesReceipt getSalesReceiptOfDate(String date) {
        return salesReceipts.get(date);
    }

    public void addSalesReceipt(SalesReceipt sr) {
        salesReceipts.put(sr.getDate(), sr);
    }

    @Override
    public double calculatePay() {
        double total = 0.0 ;
        for (SalesReceipt sr : salesReceipts.values())
            total += sr.getAmount();
        return salary + total * commission;
    }
}
